package com.isay.app.honey.ui.forget;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.isay.app.honey.R;
import com.isay.app.honey.manager.NetworkManager;
import com.isay.app.honey.ui.regist.RegisterActivity;
import com.isay.frameworklib.okhttp.ICommonCallback;
import com.isay.frameworklib.ui.BaseActivity;
import com.isay.frameworklib.utils.ToastUtils;

public class ForgetActivity extends BaseActivity implements View.OnClickListener {


    private EditText mEdtAccount;
    private EditText mEdtPwd;
    private EditText mEdtPwdSure;

    public static void launch(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, ForgetActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget);
        initView();
    }

    private void initView() {
        findViewById(R.id.tv_title).setVisibility(View.GONE);
        findViewById(R.id.iv_go_back).setOnClickListener(this);
        findViewById(R.id.btn_commit).setOnClickListener(this);
        mEdtAccount = findViewById(R.id.edt_account);
        mEdtPwd = findViewById(R.id.edt_pwd);
        mEdtPwdSure = findViewById(R.id.edt_pwd_sure);
    }

    @Override
    protected int getStatusBarColor() {
        return 0;
    }

    @Override
    protected void onCreateActivity(Bundle savedInstanceState) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_go_back:
                finish();
                break;
            case R.id.btn_commit:
                forgetPwd();
                break;
            default:
                break;
        }
    }

    private void forgetPwd() {
        showLoading("登录中...");
        final String account = mEdtAccount.getText().toString().trim();
        final String password = mEdtPwd.getText().toString().trim();
        final String passwordSure = mEdtPwdSure.getText().toString().trim();
        NetworkManager.forgetPwd(account, password, passwordSure, new ICommonCallback() {
            @Override
            public void onSuccess(int ret, String msg, String content) {
                dismissDialog();
                if (ret == 200) {
                    finish();
                    Toast.makeText(ForgetActivity.this, msg, Toast.LENGTH_SHORT).show();
                } else {
                    ToastUtils.show(msg);
                }
            }

            @Override
            public void onFailure(Exception e) {
                dismissDialog();
                ToastUtils.show(e.getMessage());
            }
        });
    }

}
